package com.chinasoft.news.controller;

import com.chinasoft.news.pojo.Code;
import com.chinasoft.news.pojo.Result;
import com.chinasoft.news.pojo.User;
import com.chinasoft.news.service.UserService;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping("/api")
@AllArgsConstructor
@CrossOrigin
public class AuthController {

    UserService userService;

    @PostMapping("/reguser")
    public Result register(User user) {
        Result result = new Result(0, "register user ok", null, Code.RegisterOk);
        System.out.println(user);
        Boolean flag = userService.registerUser(user);
        if(!flag){
            result.setStatus(1);
            result.setMessage("用户已存在，注册失败");
        }
        return result;
    }

    @PostMapping("/login")
    public Result login(User user){
//        Result result = new Result(0, "login is ok", null, Code.LoginOk);

        Result login = userService.login(user);
        return login;
    }

}
